﻿using System.Collections.Generic;
using System.Collections;
using UnityEngine;

public class SkillMgr
{

    public Dictionary<int, int> skillCD = new Dictionary<int, int>();
    public Dictionary<int, SkillInfo> skillMap;

    public SkillMgr()
    {
        Init();
    }

    private void Init()
    {
        skillMap = new Dictionary<int, SkillInfo>();
        SkillInfo[] infos = Mgr.configMgr.ReaderConfigFile<SkillInfo[]>("SkillJson");
        foreach (SkillInfo info in infos)
        {
            skillMap.Add(info.Mid, info);
        }
    }


    public void SetSkillCoolDown(int skill, int time)
    {
        skillCD.Add(skill, time);
    }

    public SkillInfo GetSkillInfo(int mid)
    {
        return skillMap[mid];
    }


    //是否在冷却中
    public bool IsSkillCoolDown(int skillId)
    {
        if (GetCoolDownTime(skillCD, skillId) == 0)
            return false;
        return true;
    }



    public int GetCoolDownTime(IDictionary map, int key)
    {
        if (!map.Contains(key))
            return 0;
        int v = (int)map[key];
        if (v != 0)
        {
            if (Time.time * 1000 > v)
            {
                map.Remove(key);
                v = 0;
            }
        }
        return v;
    }

    //==============================================
    private static SkillMgr instance;

    public static SkillMgr Instance
    {
        get
        {
            if (instance == null)
                instance = new SkillMgr();
            return instance;
        }
    }
}